Brian Hanley

45 Reputation

5 Badges

7 years, 64 days

MaplePrimes Activity


These are questions asked by Brian Hanley

mX(m, isumSD_TOT) := isumSD_REG; 
is changed to: 
mX := (m, isumSD_TOT) -> isumSD_REG;

This clobbers the Matrix mRegResTot. I can't fix it for the Matrix in the lower part. No clue why. 
The syntax works normally inside the do loops. Maple is changing the code if there is a variable that is passed as the first parm, but only outside a do loop. 

Code snippet duplicating 
_________________________________________________________________________________________

restart;
with(Statistics);
with(ArrayTools);
with(LinearAlgebra);
with(plots);
with(plottools);
with(ExcelTools);

mX := Matrix(20, 9);
iDreg := 1;
itSD_DREG := 2;
isumSD_REG := 3;
iDres := 4;
itSD_DRES := 5;
isumSD_RES := 6;
iDtot := 7;
itSD_DTOT := 8;
isumSD_TOT := 9;
for m to 20 do  # Load the matrix with values from 1 to 9. 
    mX(m, iDreg) := iDreg;
    mX(m, itSD_DREG) := itSD_DREG;
    mX(m, isumSD_REG) := isumSD_REG;
    mX(m, iDres) := iDres;
    mX(m, itSD_DRES) := itSD_DRES;
    mX(m, isumSD_RES) := isumSD_RES;
    mX(m, iDtot) := iDtot;
    mX(m, itSD_DTOT) := itSD_DTOT;
    mX(m, isumSD_TOT) := isumSD_TOT;
end do;
mX; # Show the Matrix is loaded. 
mX(5, isumSD_TOT) := itSD_DREG;  #change the last cell in the 5th row. 
mX; # Show the Matrix has row 5 column 9 changed to a 2. 
for m to 5 do #Load the first 5 rows of column 9 to a value of 1.
    mX(m, isumSD_TOT) := iDreg;
end do;
mX; # Show that the Matrix values were changed. 
m := 5;
mX(m, isumSD_TOT) := isumSD_REG;   # See syntax changed to:   mX := (m, isumSD_TOT) -> isumSD_REG;
mX;  # Show that the Matrix has been clobbered. 

 

This isn't particularly complicated. Varying the span generates graphs that are smooth or have an obvious bug. Not sure why.

This also happens if you vary the C_I_CentLim or the C_Inventory. I created this example so it is clearly happening.
The graph gets a sharp jag down, then returns to normal.

Something weird with density of points? I played with it for hours and can't get it to go away.
=============================================
restart;
L := 0;
C_Inventory := 1500;
C_I_CentLim := 0.001;
C_I_StartLim := C_Inventory*C_I_CentLim;
C_InV := Matrix(1000, 3);  # This is so you  can see values created only bobble slightly where the graph has a giant deviation.
iCounter := 0;
P_ScLdt := proc(t) local x, k; global L, C_Inventory, iCounter, C_InV; x := 0; k := 0.08; iCounter := iCounter + 1; L := C_Inventory*C_I_CentLim; x := 4.8 + L/(1 + exp(-k*(t - 2060))) + 0.050; C_InV[iCounter, 1] := L; C_InV[iCounter, 2] := C_Inventory; C_InV[iCounter, 3] := x; if 0 < x then C_Inventory := C_Inventory - x; return x; else return 0; end if; end proc;

# Show results 1800-2100  Problem.
pP_ScLdt := plot('P_ScLdt'(x), x = 1800 .. 2100, linestyle = dash, color = red, thickness = 3, axis = [gridlines = [colour = black, majorlines = 2]], legend = "Pg");

# Re-initialize.
L := 0;
C_Inventory := 1500;
C_I_CentLim := 0.001;
C_I_StartLim := C_Inventory*C_I_CentLim;
C_InV := Matrix(1000, 3);
iCounter := 0;
# Show  that problem happens with a little shorter span
pP_ScLdt := plot('P_ScLdt'(x), x = 1850 .. 2100, linestyle = solid, color = black, thickness = 1, axis = [gridlines = [colour = black, majorlines = 2]], legend = "Pg");

# Re-initialize
L := 0;
C_Inventory := 1500;
C_I_CentLim := 0.001;
C_I_StartLim := C_Inventory*C_I_CentLim;
C_InV := Matrix(1000, 3);
iCounter := 0;
# Show problem goes away with a different interval 1900-2200
pP_ScLdt := plot('P_ScLdt'(x), x = 1900 .. 2200, linestyle = dash, color = blue, thickness = 3, axis = [gridlines = [colour = black, majorlines = 2]], legend = "Pg");

# Re-initialize
L := 0;
C_Inventory := 1500;
C_I_CentLim := 0.001;
C_I_StartLim := C_Inventory*C_I_CentLim;
C_InV := Matrix(1000, 3);
iCounter := 0;
# Enlarge the working interval of 1900-2200 to 1900-2300 and the problem returns, in a different place.
pP_ScLdt := plot('P_ScLdt'(x), x = 1900 .. 2300, linestyle = dash, color = blue, thickness = 3, axis = [gridlines = [colour = black, majorlines = 2]], legend = "Pg");


# Re-initialize
L := 0;
C_Inventory := 2000;
C_I_CentLim := 0.001;
C_I_StartLim := C_Inventory*C_I_CentLim;
C_InV := Matrix(1000, 3);
iCounter := 0;

# Enlarge the interval and it causes a larger set of jaggie deviations.
pP_ScLdt := plot('P_ScLdt'(x), x = 1800 .. 2800, linestyle = solid, color = blue, thickness = 1, axis = [gridlines = [colour = black, majorlines = 2]], legend = "Pg");

X := vector([seq(x, x = 1 .. 5)]);
Y := vector([seq(x, x = 6 .. 10)]);
X[1];
Y[1];
Yfactor := evalf(X[`1`])/Y[`1`];
evalf(Yfactor);
                      X := [1, 2, 3, 4, 5]

                     Y := [6, 7, 8, 9, 10]

                               1

                               6

                                         X[1]
                        Yfactor := -------
                                         Y[1]

                              X[1]
                              ----
                              Y[1]

m := 1;
X := vector([seq(x, x = 1 .. 5)]);
Y := vector([seq(x, x = 6 .. 10)]);
Yfactor := X[m]/Y[m];
evalf(Yfactor);
                             m := 1

                      X := [1, 2, 3, 4, 5]

                     Y := [6, 7, 8, 9, 10]

                                           1
                          Yfactor := ---
                                           6

                          0.1666666667

Strange behavior. I don't know if this can be made to work.  I replaced an equation with an interpolation object, f(x).

tInt := int(f, 133  .. 134, numeric);
tInt := 324.95206944305  <= Computes a result. I

tInt := int(f, 133  .. 312, numeric);
tInt:= int(fproc, 133. .. 312.) <= Won't compute it. The interpolation object has 3051 points, so that's not the problem. The name "fproc" is not something I have in my  code, just the name, "f".

If I try to make the  integral just slightly more complex by  passing a variable in, it doesn't work at all. This was to see if I could integrate with a varying divisor: f(x)/(x+1)
int(f(x), x = 133 .. 134, numeric); 

Error, (in int) wrong number (or type) of arguments: invalid options or option values passed to definite integration. <=

A fallback  was to use summation, but that doesn't work at all, same typ of error as the Error for int. (Not shown.)

So my fallback is to use a for loop to sum the set. The for loops produce another set of values, and I think I have to make interpolation objects for that as well. And so on. I really  was expecting  Maple to handle this better.

I want to do some memory management in Maple for large arrays.

To clarify this question: What do I have to do in Maple to free memory allocated to an array? The indications I have are that memory probably is not freed, but rather a new variable of null is created that replaces the old one, but the old one is still sitting around.

1 2 Page 1 of 2